
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


<script type="text/javascript">
    //$.noConflict();
    $(window).resize(function() {
        $('#grid_pump').datagrid('resize');
    });

    function clearPumpForm(){
        $('#pumpForm').form('clear');
    }
	
	function clear_img(){
		$('#p_img_img').attr('src', '__PUBLIC__/img/no_pic.jpg');
	}


    function clearQueryParamZone(){
        $('#queryForm_Pump').form('clear');
    }

    $(function(){
        $('#ps_id_combox').combobox({
            url:'/Manage/AdminCsdt/get_all_combox',
            valueField:'id',
            textField:'name'
        });
        $('#grid_pump').datagrid({
            //title:'水泵',
            width: '100%',
            //height: 400,
            fit: true,
            nowrap: false,
            striped: true,
            collapsible:false,
            url:'/Manage/AdminCsdtPump/get_all',
            queryParams:{page:1,rows:20},
            method:'get',
            pageNumber:1,
            pageSize:20,
            idField:'id',
            sortName: 'id',
            sortOrder: 'desc',
            remoteSort: true,
            columns:[[
                {field:'id',title:'序号',width:60,checkbox:true},
                {field:'sta_name',title:'调蓄池名称',width:180,align:'center'},
                {field:'p_name',title:'泵机名称',width:100,align:'center'},
                {field:'p_number',title:'泵机编号',width:80,align:'center'},
                {field:'p_mfr',title:'泵机厂家',width:100,align:'center'},
                {field:'p_type',title:'泵机类型',width:80,align:'center'},
                {field:'p_model',title:'泵机型号',width:80,align:'center'},
                {field:'p_strt_mode',title:'启动方式',width:80,align:'center'},
                {field:'p_flow_meas',title:'实测流量（㎥／h）',width:100,align:'center'},
                {field:'p_power_dsgn',title:'设计功率（千瓦）',width:120,align:'center'},
                {field:'p_head_dsgn',title:'设计扬程（m）',width:80,align:'center'},
                {field:'p_work_v',title:'工作电压（伏）',width:140,align:'center'},
                {field:'p_work_a',title:'工作电流（安培）',width:140,align:'center'},
            ]],
            pagination:true,
            rownumbers:true,
            singleSelect:false,
            toolbar: '#grid_pump_ToolBar',
            onDblClickRow: function(rowIndex, rowData) {
                var selected = $('#grid_pump').datagrid('getSelected');
                if($('#single').is(":hidden")){
                    editPump(rowData.id);
                }else{
                    var rows = $('#grid_pump').datagrid('getSelections');
                    if(selected){
                        if(selected.id == rowData.id){
                            editPump(rowData.id);
                        }else{
                            $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                        }
                    }else{
                        editPump(rowData.id);
                    }
                }
            },
            onSelect: function(rowIndex, rowData) {
                var now_rows = jQuery('#grid_pump').datagrid('getSelections');
                if(now_rows.length > 1){
                    $("#btnEditPump").linkbutton('disable');
                }
            },
            onUnselect: function(rowIndex, rowData) {
                var now_rows = jQuery('#grid_pump').datagrid('getSelections');
                if(now_rows.length < 2){
                    $("#btnEditPump").linkbutton('enable');
                }
            },
            onLoadSuccess: function(data) {
                $(this).datagrid('resize');
            }
        });

        $('#btnAddPump').click(function() {
            clearPumpForm();
			clear_img();
            $("#saveflag_pump").val("add");
            $('#ps_id_combox_1').combobox({
                url:'/Manage/AdminCsdt/get_all_combox',
                valueField:'id',
                textField:'name'
            });
            $('#pumpDlg').dialog({title:'录入泵机信息',modal:true});
            $('#pumpDlg').dialog("open");
        });
        $('#btnEditPump').click(function() {
            var selected = $('#grid_pump').datagrid('getSelected');
            if($('#single').is(":hidden")){
                if (selected) {
                    editPump(selected.id);
                }
            }else{
                var rows = $('#grid_pump').datagrid('getSelections');
                if(rows.length == 1 || rows.length == 0){
                    if (selected) {
                        editPump(selected.id);
                    }
                    else{
                        $.messager.show({title: "提示",msg: "请选中一条信息，再进行编辑!"});
                    }
                }else{
                    $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                    singleToggle();
                }
            }
        });
        $('#btnDelPump').click(function() {
            var ids = [];
            var rows = $('#grid_pump').datagrid('getSelections');
            for ( var i = 0; i < rows.length; i++) {
                ids.push(rows[i].id);
            }
            if ((ids != null) && (ids.length > 0)) {
                $.messager.confirm('请确认', '你确定要删除吗？', function(r) {
                    if (r) {

                        $('#batchDelForm').ajaxSubmit({
                            url:"/Manage/AdminCsdtPump/deleteArray",
                            data:{'ids':ids.join(',')},
                            dataType:'json',
                            success: function(data) {
                                if (data.status==1) {
                                    $('#grid_pump').datagrid('reload');
                                    $('#grid_pump').datagrid("unselectAll");
                                    $.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
                                }
                                else $.messager.alert('提示','删除失败！','error');
                            }
                        });
                    }
                });
            }
        });
        $('#btnSearchPump').click(function() {
            $('#queryParamZone_pump').toggle();
            $('#grid_pump').datagrid("resize");
        });

        $('#btnQueryPump').click(function() {
            var obj = $('#queryForm_Pump').serializeJson();
            $('#grid_pump').datagrid('load',obj);
        });

        var model = 'PumpPump';
        table_index_change(model, 'base');

        $('#queryParamZone_pump').hide();
        $('#single').hide();
    });

    function editPump(id) {
        if(id!=""){
            $("#saveflag_pump").val("update");
        }else{
            clearPumpForm();
            $("#saveflag_pump").val("add");
            return;
        }
		clear_img();
        $.ajax({url:"/Manage/AdminCsdtPump/get_obj_json",data:{id:id},dataType:"json",success:function(json, textStatus){
            $('#ps_id_combox_1').combobox({
                url:'/Manage/AdminCsdt/get_all_combox',
                valueField:'id',
                textField:'name'
            });
            $('#pumpForm').form('load',{
                "id": json.id,
                'ps_id':json.ps_id,
                "p_id": json.p_id,
                "p_name": json.p_name,
                "p_mfr": json.p_mfr,
                "p_model": json.p_model,
                "p_flow_dsgn": json.p_flow_dsgn,
                "p_flow_meas": json.p_flow_meas,
                "p_head_dsgn": json.p_head_dsgn,
                "p_head_meas": json.p_head_meas,
                "p_power_dsgn": json.p_power_dsgn,
                "p_power_meas": json.p_power_meas,
                "p_rev": json.p_rev,
                "p_work_v": json.p_work_v,
                "p_work_a": json.p_work_a,
                "p_strt_dep": json.p_strt_dep,
                "p_stop_dep": json.p_stop_dep,
                "p_strt_mode": json.p_strt_mode,
                "p_curve": json.p_curve,
                "p_pur_dt": json.p_pur_dt,
                "p_svc_dt": json.p_svc_dt,
                "p_img": json.p_img,
                "p_number": json.p_number,
                "p_type": json.p_type,
            });
            if(json.p_img != ''){
                $('#p_img_img').attr('src', json.p_img);
            }
            $('#pumpDlg').dialog({title:'编辑泵机信息',modal:true});
            $('#pumpDlg').dialog("open");
            setFormFocus('#pumpForm');
        },error:function(XMLHttpRequest, textStatus, errorThrown)
        {
            relogin(XMLHttpRequest, textStatus, errorThrown);
        }});
    }

    function submitPumpForm() {
        if ($('#pumpForm').form('validate')) {
            var submitflag = $("#saveflag_pump").val();
            var url = "";
            console.log(submitflag);
            if (submitflag === "add")
                url = "/Manage/AdminCsdtPump/add";
            if (submitflag === "update")
                url = "/Manage/AdminCsdtPump/edit";
            $('#pumpForm').ajaxSubmit({
                url:url,
                dataType:'json',
                success: function(data) {
                    if (data.status==1) {
                        if (submitflag === "add") $('#grid_pump').datagrid('load');
                        if (submitflag === "update") $('#grid_pump').datagrid('reload');
                        $('#pumpDlg').dialog("close");
                        $.messager.show({title:'提示',msg:'保存成功！',showType:'slide'});
                    }
                    else $.messager.alert('提示','操作失败！','error');
                }
            });
        }
    }
</script>
<table id="grid_pump"></table>
<div id="grid_pump_ToolBar" style="padding:5px;height:auto">
    <div style="margin-bottom:5px">

        <a id="btnAddPump" href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true">增加</a>
        <a id="btnEditPump" href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
        <a id="btnDelPump" href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
        <a id="btnSearchPump" href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
        <a id="btnReload" href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="$('#grid_pump').datagrid({url:'/Manage/AdminCsdtPump/get_all',queryParams:{'ps_id':$('#pumpstation_id').val(),page:1,rows:20}})">重载</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-import" plain="true" onclick="open_dialog('/Manage/Admin/open_window_import?url=/Manage/AdminCsdtPump/import')">导入</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-rescueLog" plain="true" onclick="open_tab('/Manage/AdminCsdtPump/export')">导出</a>
    </div>
    <div id="queryParamZone_pump">
        <form id="queryForm_Pump" method="post" action="">
            <table>
                <tr>
                    <td>调蓄池</td>
                    <td><input id="ps_id_combox" name="ps_id"></td>
                    <td>泵机属性</td>
                    <td id="table_field">
                        <input class="easyui-combobox"/>
                    </td>
                    <td>查询条件</td>
                    <td id="condition_td">
                        <input type="text"/>
                    </td>

                    <td><a id="btnQueryPump" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
                    <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#queryForm_Pump').form('clear');">重置</a></td>
                </tr>
            </table>

        </form>
    </div>
</div>
<div id="pumpDlg" class="easyui-dialog" title="" style="width:650px;height:450px;padding:10px" buttons="#dlg-buttons-pump" closed="true" resizable="true">
    <form id="pumpForm" method="post" action="">
        <input id="saveflag_pump" name="saveflag_pump" type="hidden" value="add"/>
        <input type="hidden" name="id" />
        <table border="0">
            <tr>
                <td align="right">调蓄池名称：</td>
                <td>
                    <input id="ps_id_combox_1" name="ps_id" required="true" style="width: 180px;">
                </td>
            </tr>
            <tr>
                <td align="right">泵机名称：</td>
                <td>
                    <input class="easyui-validatebox" validType="maxLength[30]" type="text" name="p_name" required="true"></input>
                </td>
                <td align="right">泵机类型：</td>
                <td>
                    <select class="easyui-combobox" name="p_type" id="type" data-options="prompt:'{:LANG('pls_input')}',required:true" style="width: 140px;">
                        {:pump_pump_type_option()}
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">泵机编号：</td>
                <td>
                    <input class="easyui-textbox" type="text" name="p_number" style="width: 140px;" required="true"></input>
                </td>
                <td align="right">设备ID：</td>
                <td>
                    <input class="easyui-textbox" type="text" name="p_id" style="width: 140px;"></input>
                </td>
            </tr>
            <tr>
                <td align="right">泵机厂家：</td>
                <td>
                    <input class="easyui-validatebox" validType="maxLength[50]" type="text" name="p_mfr"></input>
                </td>
                <td align="right">购买时间：</td>
                <td>
                    <input type="text" class=" easyui-datebox" name="p_pur_dt" style="width:140px">
                </td>
            </tr>
            <tr>
                <td align="right">泵机型号 ：</td>
                <td>
                    <input class="easyui-validatebox" type="text" name="p_model"></input>
                </td>
                <td align="right">启动方式：</td>
                <td>
                    <select class="easyui-combobox" name="p_strt_mode" data-options="prompt:'{:LANG('pls_input')}'" required="true" style="width: 140px;">
                        {:pump_pump_usemodel_option()}
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">设计流量（㎥／h）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="p_flow_dsgn" precision="4" style="width: 150px;"></input>
                </td>
                <td align="right">实测流量（㎥／h）：</td>
                <td>
                    <input class="easyui-numberbox easyui-validatebox" type="text" name="p_flow_meas" precision="4" style="width: 150px;" required="true"></input>
                </td>
            </tr>
            <tr>
                <td align="right">设计扬程（m）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="p_head_dsgn" precision="4" style="width: 150px;"></input>
                </td>
                <td align="right">实测扬程（m）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="p_head_meas" precision="4" style="width: 150px;"></input>
                </td>
            </tr>
            <tr>
                <td align="right">设计功率（kw）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="p_power_dsgn" precision="4" style="width: 150px;"></input>
                </td>
                <td align="right">实测功率（kw）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="p_power_meas" precision="4" style="width: 150px;"></input>
                </td>
            </tr>
            <tr>
                <td align="right">工作电压（伏）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="p_work_v" precision="4" style="width: 150px;"></input>
                </td>
                <td align="right">工作电流（安）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="p_work_a" precision="4" style="width: 150px;"></input>
                </td>
            </tr>
            <tr>
                <td align="right">启泵水深（m）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="p_strt_dep" precision="4" style="width: 150px;"></input>
                </td>
                <td align="right">停泵水深（m）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="p_stop_dep" precision="4" style="width: 150px;"></input>
                </td>
            </tr>
            <tr>
                <td align="right">转速（转/分）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="p_rev" precision="4" style="width: 150px;"></input>
                </td>
                <td align="right">工作曲线（m）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="p_curve" style="width: 150px;"></input>
                </td>
            </tr>
            <tr>
                <td align="right">投运日期：</td>
                <td>
                    <input type="text" class=" easyui-datebox" name="p_svc_dt" style="width:140px">
                </td>
                <td>
                    <input id="p_img_button" type="file" multiple="true" value="" />
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <input type="hidden" id="p_img" name="p_img"/>
                    <img src="__PUBLIC__/img/no_pic.jpg" id="p_img_img" width="100" height="200">
                    <script>
                        $('#p_img_button').uploadify({
                            'swf'      : '/Public/uploadfy/uploadify.swf',
                            'uploader' : '/Manage/Admin/uploadify',
                            'buttonText' : '上传泵机图',
                            'onUploadSuccess' : function(file, data, response) {
                                var imgname = data.trim();
                                $('#p_img_img').attr('src', data);
                                $('#p_img').val(data);
                            }
                        });
                    </script>
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="dlg-buttons-pump" style="text-align: center;">
    <a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="javascript:submitPumpForm();">保存</a>
</div>
<form id="batchDelForm" method="post">
    <input id="ids" type="hidden" name="ids"/>
</form>